package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.*;
import com.atguigu.gmall.product.service.ManagerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product")
@Api(value = "商品基础开发接口")
//@CrossOrigin//允许跨域 网关处配置了全局跨域
public class BaseManagerController {

    @Autowired
    private ManagerService managerService;

    @GetMapping("/getAttrValueList/{attrId}")
    @ApiOperation("根据属性id查询属性集合")
    public Result getAttrValueList(@PathVariable Long attrId){
        BaseAttrInfo baseAttrInfo=managerService.getAttrInfo(attrId);
        List<BaseAttrValue> list=baseAttrInfo.getAttrValueList();
        return Result.ok(list);
    }

    @PostMapping("/saveAttrInfo")
    @ApiOperation("新增和修改平台属性")
    public Result saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo){
        managerService.saveAttrInfo(baseAttrInfo);
        return Result.ok();
    }

    /**
     * 查询一级分类
     * @return
     */
    @GetMapping("/getCategory1")
    @ApiOperation("查询一级分类")
    public Result getCategory1(){
        List<BaseCategory1> baseCategory1List=managerService.getCategory1();
        return Result.ok(baseCategory1List);
    }

    @GetMapping("/getCategory2/{category1Id}")
    @ApiOperation("查询二级分类")
    public Result getCategory2(@PathVariable Long category1Id){
        List<BaseCategory2> baseCategory2List=managerService.getCategory2(category1Id);
        return Result.ok(baseCategory2List);
    }

    @GetMapping("/getCategory3/{category2Id}")
    @ApiOperation("查询三级分类")
    public Result getCategory3(@PathVariable Long category2Id){
        List<BaseCategory3> baseCategory3List=managerService.getCategory3(category2Id);
        return Result.ok(baseCategory3List);
    }

    @GetMapping("/attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    @ApiOperation("根据分类查询平台属性")
    public Result attrInfoList(@PathVariable Long category1Id,
                               @PathVariable Long category2Id,
                               @PathVariable Long category3Id){
        List<BaseAttrInfo> list=managerService.attrInfoList(category1Id,category2Id,category3Id);
        return Result.ok(list);
    }


}
